package com.bsoft.coordinatorlayouttest;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 泅渡者
 * Created on 2017/10/19.
 */

public class CollapsingToolbarLayoutAndAppBarLayoutSimple extends AppCompatActivity {

    private RecyclerView recyclerView;
    private RecyclerAdapter recyclerAdapter;
    private List<String> mlist;
    private CoordinatorLayout main_content;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_collapsing_appbarlayout);
        initView();
    }

    private void initView() {

        CollapsingToolbarLayout collapsingToolbarLayout = (CollapsingToolbarLayout)findViewById(R.id.collapsing_toolbar);
        collapsingToolbarLayout.setTitle("Collapsing");



        mlist = new ArrayList<>();
        for (int i = 1; i < 100; i++) {
            mlist.add("第" + i + "行");
        }
        recyclerView = (RecyclerView) findViewById(R.id.rvToDoList);
        main_content = (CoordinatorLayout) findViewById(R.id.main_content);

        recyclerAdapter = new RecyclerAdapter(this,mlist);
        recyclerView.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.setAdapter(recyclerAdapter);
        recyclerAdapter.setOnItemClickLitener(new RecyclerAdapter.OnItemClickLitener() {
            @Override
            public void onItemClick(View view, int position) {
                Snackbar.make(main_content, mlist.get(position), Snackbar.LENGTH_LONG)
                        .setAction(R.string.snackbar_action, null)
                        .setActionTextColor(getResources().getColor(R.color.colorAccent))
                        .setDuration(3000).show();
            }
        });

    }

}
